package com.matrix.math;


import java.text.DecimalFormat;
import java.util.ArrayList;

import junit.framework.TestCase;
import junit.framework.Assert;


public class MatrixTest extends TestCase {

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	public void testNullSpace1() {
		double[][] a = {{1,3,7,-3},{4,2,8,8},{-3,1,-1,-11},{0,0,0,0}};
		Matrix A = new Matrix("A", a);
		double[] c1 = {-1,-2,1,0};
		double[] c2 = {-3,2,0,1};
		ColumnVector C1 = new ColumnVector("C1", c1);
		ColumnVector C2 = new ColumnVector("C2", c2);
		try {
			ArrayList<ColumnVector> nullsp = A.nullSpace();
			
			if(!nullsp.get(0).equals(C1))
			{
				fail();
			}
			if(!nullsp.get(1).equals(C2))
			{
				fail();
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		
	}
	public void testNullSpace2() {
		double[][] a = {{1,-2,3,1},{3,-7,11,3},{4,-9,14,4},{0,0,0,0}};
		Matrix A = new Matrix("A", a);
		double[] c1 = {1,2,1,0};
		double[] c2 = {-1,0,0,1};
		ColumnVector C1 = new ColumnVector("C1", c1);
		ColumnVector C2 = new ColumnVector("C2", c2);
		try {
			ArrayList<ColumnVector> nullsp = A.nullSpace();
			
			if(!nullsp.get(0).equals(C1))
			{
				fail();
			}
			if(!nullsp.get(1).equals(C2))
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		
	}
	public void testNullSpace3() {
		double[][] a = {{1,2}, {7,5}};
		Matrix A = new Matrix("A", a);
		try {
			//System.out.println(A.getValueAt(1, 1));
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			//System.out.println(A.inverse().getValueAt(1, 0));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		
		
	}
	public void testaxbSolve1() 
	{
		
		double[][] a = {{6,2,1},{18,9,5},{12,16,14}};
		double[] v = {10,29,32};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {2, -3, 4};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				l.get(0).print();
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve2() 
	{
		double[][] a = {{0,7,-1},{3,1,1},{15,-9,9}};
		double[] v = {16,11,33};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {1,3,5};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve3() 
	{
		double[][] a = {{5,-2,3,-1},{1,3,2,6},{3,0,9,12},{1,0,3,-5}};
		double[] v = {0,15,9,-6};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {2,3,-1,1};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve4() 
	{
		double[][] a = {{-11,3,5,-1,1},{3,5,6,2,-3},{6,4,7,-3,-1},{0,1,4,8,-9},{1,0,3,5,2}};
		double[] v = {-23,9,66,18,16};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {3.907430730478590,-15.017002518891700, 12.530384130982400, -4.322890428211590,-1.942065491183880};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve5() 
	{
		double[][] a = {{1,3,-3},{2,-1,8},{3,2,5}};
		double[] v = {-3,24,21};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 2)
			{
				fail();
			}
			double[] v2 = {-3.0+90.0/7.0,-30.0/7.0,0};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
			double[] v3 = {-3,2,1};
			ColumnVector c = new ColumnVector("c", v3);
			if(!c.equals(l.get(1)))
			{
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve6() 
	{
		double[][] a = {{1,3,0,2},{0,0,1,4},{1,3,1,6}};
		double[] v = {1,6,7};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 3)
			{
				fail();
			}
			double[] v2 = {1,0,6,0};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
			double[] v3 = {-3,1,0,0};
			ColumnVector c = new ColumnVector("c", v3);
			if(!c.equals(l.get(1)))
			{
				fail();
			}
			double[] v4 = {-2,0,-4,1};
			ColumnVector c2 = new ColumnVector("c", v4);
			if(!c2.equals(l.get(2)))
			{
				l.get(2).print();
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve7() 
	{
		double[][] a = {{1,-2,3,1},{3,-7,11,3},{4,-9,14,4}};
		double[] v = {4,14,18};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 3)
			{
				fail();
			}
			double[] v2 = {0,-2,0,0};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				fail();
			}
			double[] v3 = {1,2,1,0};
			ColumnVector c = new ColumnVector("c", v3);
			if(!c.equals(l.get(1)))
			{
				fail();
			}
			double[] v4 = {-1,0,0,1};
			ColumnVector c2 = new ColumnVector("c", v4);
			if(!c2.equals(l.get(2)))
			{
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve8() 
	{
		
		double[][] a = {{6,2,1},{18,9,5},{12,16,14},{12,4,2}};
		double[] v = {10,29,32,20};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {2, -3, 4};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				l.get(0).print();
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testaxbSolve9() 
	{
		
		double[][] a = {{6,2,1},{18,9,5},{12,4,2},{12,16,14}};
		double[] v = {10,29,20,32};
		Matrix A = new Matrix("A", a);
		ColumnVector b = new ColumnVector("b", v);
		try{
			ArrayList<ColumnVector> l = A.axbSolve(b);
			if(l.size() != 1)
			{
				fail();
			}
			double[] v2 = {2, -3, 4};
			ColumnVector x = new ColumnVector("x", v2);
			if(!x.equals(l.get(0)))
			{
				l.get(0).print();
				fail();
			}
		}catch(Exception e)
		{
			e.printStackTrace();
			fail();
		}
	}
	public void testPLU1() {
		double[][] a = {{4,3},{6,3}};
		Matrix A = new Matrix("A", a);
		try {
			ArrayList<Matrix> mList = A.pluFactorization();
			double[][] p = {{1,0},{0,1}};
			double[][] l = {{1,0},{1.5,1}};
			double[][] u = {{4,3},{0,-1.5}};
			Matrix P = new Matrix("P" , p);
			Matrix L = new Matrix("L", l);
			Matrix U = new Matrix("U", u);
			if(!mList.get(0).equals(P) || !mList.get(1).equals(L) || !mList.get(2).equals(U))
			{
				fail();
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		
	}
	public void testPLU2() {
		double[][] a = {{0,7,-1},{3,1,1},{15,-9,9}};
		Matrix A = new Matrix("A", a);
		try {
			ArrayList<Matrix> mList = A.pluFactorization();
			double[][] p = {{0,1,0},{1,0,0},{0,0,1}};
			double[][] l = {{1,0,0},{0,1,0},{5,-2,1}};
			double[][] u = {{3,1,1},{0,7,-1},{0,0,2}};
			Matrix P = new Matrix("P" , p);
			Matrix L = new Matrix("L", l);
			Matrix U = new Matrix("U", u);
			if(!mList.get(0).equals(P) || !mList.get(1).equals(L) || !mList.get(2).equals(U))
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
		
	}
	public void testPLU3() {
		double[][] a = {{2,2},{2,2}};
		Matrix A = new Matrix("A",a);
		try {
			ArrayList<Matrix> mList = A.pluFactorization();
			double[][] p = {{1,0},{0,1}};
			double[][] l = {{1,0},{1,1}};
			double[][] u = {{2,2},{0,0}};
			Matrix P = new Matrix("P" , p);
			Matrix L = new Matrix("L", l);
			Matrix U = new Matrix("U", u);
			if(!mList.get(0).equals(P) || !mList.get(1).equals(L) || !mList.get(2).equals(U))
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
	}
	public void testPLU4() {
		double[][] a = new double[10][10];
		double[][] p = new double[10][10];
		double[][] l = new double[10][10];
		double[][] u = new double[10][10];
		for(int i=0; i<10; i++)
		{
			u[i][i]= a[i][i] = 2;
			p[i][i] = l[i][i] = 1;
		}
		Matrix A = new Matrix("A",a);
		try {
			ArrayList<Matrix> mList = A.pluFactorization();
			Matrix P = new Matrix("P" , p);
			Matrix L = new Matrix("L", l);
			Matrix U = new Matrix("U", u);
			if(!mList.get(0).equals(P) || !mList.get(1).equals(L) || !mList.get(2).equals(U))
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
	}
	/**
	 * test that the base case is caught and correct det is returned
	 */
	public void testDeterminant1() {
		double[][] a = new double[2][2];
		a[0][0] = 2;
		a[1][0] = 2;
		a[0][1] = 2;
		a[1][1] = 2;
		Matrix m = new Matrix("A",a);
		try {
			if(m.determinant()!=0)
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			fail();
		}
	}
	/**
	 * test to checks that the det of a 3x3 matrix is found
	 */
	public void testDeterminant2() {
		double[][] a = new double[3][3];
		a[0][0] = 1;
		a[0][1] = 2;
		a[0][2] = 3;
		a[1][0] = 5;
		a[1][1] = 6;
		a[1][2] = 7;
		a[2][0] = 6;
		a[2][1] = 7;
		a[2][2] = 8;
		Matrix m = new Matrix("A",a);
		double det =0;
		try {
			det = m.determinant();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(det!=0)
		{
			fail();
		}
	}
	/**
	 * creates a 10x10 diag matrix and check to see if it gets the correct det
	 */
	public void testDeterminant3() {
		double[][] a = new double[10][10];
		for(int i=0; i<10; i++)
		{
			a[i][i] = 2;
		}
		Matrix m = new Matrix("A",a);
		double det =0;
		try {
			det = m.determinant();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(det!=1024)
		{
			fail();
		}
	}
	/**
	 * creates a 10x10 upper triangular matrix and checks to see if it gets the correct det
	 */
	public void testDeterminant4() {
		double[][] a = new double[10][10];
		for(int i=0; i<10; i++)
		{
			for(int j=i; j<10; j++)
			{
				a[i][j] = (i+1)*(j+1);
			}
		}
		Matrix m = new Matrix("A",a);
		double det =0;
		try {
			det = m.determinant();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(det!=13168189440000.0)
		{
			fail();
		}
	}
	/**
	 * checks to make sure that a non nxn matrix returns a det of 0
	 */
	public void testDeterminant5() {
		double[][] a = {{2,2,2},{2,2,2}};
		Matrix m = new Matrix("A",a);
		double det =0;
		try {
			det = m.determinant();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(det!=0)
		{
			fail();
		}
	}
	public void testDeterminant6() {
		double[][] a = new double[10][10];
		for(int i=0; i<10; i++)
		{
			a[i][i] = -9999999999999999999999999999999.0;
		}
		Matrix m = new Matrix("A",a);
		double det =0;
		try {
			det = m.determinant();
			//System.out.println(det);
			fail();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
	}

	/**
	 * checks to see if base case works all answers are 2
	 * @throws Exception 
	 */
	 public void testaddVector1() throws Exception {
		 Vector v = new Vector();
		 double[] t1 = {1,1,1};
		 double[] t2 = {1,1,1};
		 double[] expected = {2,2,2};

		 double[] sum = v.addVector(t1,t2);
		 for(int i = 0; i < expected.length; ++i)
		 {
			 assertEquals(expected[i], sum[i], 1e-15);
		 }
		 
	 }
	 
	 /**
	 * tests same size vector requirement 11 is error code
	 * @throws Exception 
	 */
	 public void testaddVector2() throws Exception {
		 Vector v = new Vector();
		 double[] t1 = new double[3];
		 double[] t2 = new double[2];
		 t1[0] = 1;
		 t1[1] = 1;
		 t1[2] = 1;
		 
		 t2[0] = 1;
		 t2[1] = 1;
		 
		 double[] sum = v.addVector(t1,t2);
		 if(sum[0] != 11)
		 {
			 fail(); 
		 }
	
		 
	 }	
		 
	 /**
	 * checks to see if handles negative numbers correctly all values
	 * should be 2.
	 * @throws Exception 
	 */
	 public void testaddVector3() throws Exception {
		 Vector v = new Vector();
		 double[] t1 = new double[3];
		 double[] t2 = new double[3];
		 t1[0] = -1;
		 t1[1] = 1;
		 t1[2] = -1;
		 
		 t2[0] = 3;
		 t2[1] = 3;
		 t2[2] = 3;
		 double[] sum = v.addVector(t1,t2);
		 if(sum[0] != 2)
		 {
			 fail(); 
		 }
		 if(sum[1] != 4)
		 {
			 fail(); 
		 }
		 if(sum[2] != 2)
		 {
			 fail(); 
		 }
		 
		 sum = v.addVector(t2,t1);
		 if(sum[0] != 2)
		 {
			 fail(); 
		 }
		 if(sum[1] != 4)
		 {
			 fail(); 
		 }
		 if(sum[2] != 2)
		 {
			 fail(); 
		 }
	 }	
			 
	 /**
	 * tests that vectors cannot be too large.
	 * @throws Exception 
	 */
	 public void testaddVector4() throws Exception {
		 Vector v = new Vector();
		 double[] t1 = new double[4];
		 double[] t2 = new double[3];
		 t1[0] = 1;
		 t1[1] = 1;
		 t1[2] = 1;
		 t1[3] = 1;
		 
		 t2[0] = 1;
		 t2[1] = 1;
		 t2[2] = 1;
		 
		 
		 
		 double[] sum = v.addVector(t1,t2);
		 if(sum[0] != 11)
		 {
			 fail(); 
		 }
	 }
	 /**
		 * tests that vectors cannot be too small.
	 * @throws Exception 
		 */
	 public void testaddVector5() throws Exception {
		 Vector v = new Vector();
		 double[] t1 = new double[3];
		 double[] t2 = new double[1];
		 t1[0] = 1;
		 t1[1] = 1;
		 t1[2] = 1;
		 
		 t2[0] = 1;
		 
		 
		 double[] sum = v.addVector(t1,t2);
		 if(sum[0] != 11)
		 {
			 fail(); 
		 }
	
		 
	 }
	
	/**
    * tests that the base case is caught and correct product is returned
    */
    public void testmultMatrix1()
      {
        double[][] a = {{2,2},{2,2}};
        double[][] b = {{1,1},{1,1}};
        Matrix m = new Matrix("A",a);
        Matrix m2 = new Matrix("B",b);
        double[][] test = {{4,4},{4,4}};
        Matrix m3 = new Matrix("test",test);
        Matrix c;
		try {
			c = m.multMatrix(m2);
			if (!c.equals(m3))
	        {
	          fail();
	        }
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        
  }
  
   /**
    * creates two 3x3 matrices and checks if the product is correct
 * @return 
    */
    public void testmultMatrix2()
    {
    	double[][] a = new double[3][3];
    	double[][] b = new double[3][3];
    	
    	for(int i=0; i<3; i++)
    	{
    		for(int j=0; j<3; j++)
    		{
               a[i][j] = b[i][j] = (i+1)*(j+1);
            }
    	}

    	Matrix m = new Matrix("A",a);
    	Matrix m2 = new Matrix("B",b);
    	double[][] test = {{14,28,42},{28,56,84},{42,84,126}};
    	Matrix m3 = new Matrix("test", test);
    	Matrix product = null;
    	
    	try {
    		product = m.multMatrix(m2);
    	} catch (Exception e) {
			// TODO Auto-generated catch block
    		e.printStackTrace();
		}
         
    	try {
			if (!product.equals(m3))
			{
				fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  }

  /**
    * creates an nxm and an mxk matrix and checks if the product is correct
    */
    public void testmultMatrix4()
    {
    	double[][] a = new double[2][3];
    	double[][] b = new double[3][4];
    	
    	for(int i=0; i<2; i++)
    	{
    		for(int j=0; j<3; j++)
    		{
    			a[i][j] = (i+1)*(j+1);
            }
    	}
    	
    	for(int i=0; i<3; i++)
    	{
    		for(int j=0; j<4; j++)
            {
    			b[i][j] = (i+1)*(j+1);
            }
    	}
        Matrix m = new Matrix("A",a);
        Matrix m2 = new Matrix("B",b);
        double[][] test = {{14, 28, 42, 56},{28, 56, 84,112}};
        Matrix m3 = new Matrix("test",test);
        Matrix product = null;
        try {
        	product = m.multMatrix(m2);
        	if (!product.equals(m3))
			{
				fail();
			}
        } catch (Exception e) {
        	// TODO Auto-generated catch block
        	e.printStackTrace();
        }
    }
    /**
     * creates a 10x10 matrix and checks to see if it has the correct product
     */
    public void testmultMatrix5()
    {
    	double[][] a = new double[10][10];
    	double[][] b = new double[10][10];
      
    	for(int i=0; i<10; i++)
        {
           for(int j=0; j<10; j++)
           {
              a[i][j] = b[i][j] = (i+1)*(j+1);
           }
        }
    	Matrix m = new Matrix("A",a);
    	Matrix m2 = new Matrix("B",b);
        final double[][] test = {{385,770,1155,1540,1925,2310,2695,3080,3465,3850},{770,1540,2310,3080,3850,4620,5390,6160,6930,7700},{1155,2310,3465,4620,5775,6930,8085,9240,10395,11550},{1540,3080,4620,6160,7700,9240,10780,12320,13860,15400},{1925,3850,5775,7700,9625,11550,13475,15400,17325,19250},{2310,4620,6930,9240,11550,13860,16170,18480,20790,23100},{2695,5390,8085,10780,13475,16170,18865,21560,24255,26950},{3080,6160,9240,12320,15400,18480,21560,24640,27720,30800},{3465,6930,10395,13860,17325,20790,24255,27720,31185,34650},{3850,7700,11550,15400,19250,23100,26950,30800,34650,38500}};
        Matrix m3 = new Matrix("test",b);
        Matrix product = null;
		try {
			product = m.multMatrix(m2);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        try {
			if(product.equals(m3))
			{
			   fail();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  }
    
    /*
	 * Method to check the base case for adding two matrices together
	 */
	public void testaddMatrix1()        {            
		
		double[][] a = new double[2][2];          
		double[][] b = new double[2][2];    
		a[0][0] = 3;          
		a[1][0] = 3;          
		a[0][1] = 3;          
		a[1][1] = 3;                    
		
		b[0][0] = 2;          
		b[1][0] = 2;          
		b[0][1] = 2;          
		b[1][1] = 2;                    
		Matrix m = new Matrix("A",a);
		Matrix m2 = new Matrix("B",b);
		double[][] testMatrix = new double[2][2];    
		testMatrix[0][0] = 5;          
		testMatrix[1][0] = 5;          
		testMatrix[0][1] = 5;          
		testMatrix[1][1] = 5;                    
		Matrix m3 = new Matrix("test",testMatrix);
		Matrix c = null;
		try {
			c = m.add(m2);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}                    
		
		try {
			if (!c.equals(m3))
			{            
			
				fail();  
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

		/*
		 * Method to check that a 10x10 matrix is added correctly
		 */
		public void testaddMatrix2()        {      
			
			double[][] a = new double[10][10]; 
		    double[][] b = new double[10][10];    
		    for(int i=0; i<10; i++)  {  
			
		    	for(int j=0; j<10; j++)  {  
			
		    		a[i][j] = (i+1)+(j+1);
		    	}  
		    	//System.out.println();
			}    
			for(int i=0; i<10; i++)  {  
			
				for(int j=0; j<10; j++)  {  
			
					b[i][j] = (i+1)+(j+1);  
				}  
			}    
			Matrix m = new Matrix("A",a);
			Matrix m2 = new Matrix("B",b);
			double[][] testMatrix = {{4, 6, 8, 10, 12, 14, 16, 18, 20, 22},{6,8,10,12,14,16,18,20,22,24},{8,10,12,14,16,18,20,22,24,26},{10,12,14,16,18,20,22,24,26,28},{12,14,16,18,20,22,24,26,28,30},{14,16,18,20,22,24,26,28,30,32},{16,18,20,22,24,26,28,30,32,34},{18,20,22,24,26,28,30,32,34,36},{20,22,24,26,28,30,32,34,36,38},{22,24,26,28,30,32,34,36,38,40}};
			Matrix m3 = new Matrix("test",testMatrix);
			Matrix addition = null;
			try {
				addition = m.add(m2);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
			
			try {
				if(!addition.equals(m3))
				{  
					fail();
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}  
		}
		/*
		 * Method to check the base case for subtracting two matrices together
		 */

		public void testSubtractMatrix1()        {          
			
			double[][] a = new double[2][2];          
			double[][] b = new double[2][2];          
			
			a[0][0] = 3;          
			a[1][0] = 3;          
			a[0][1] = 3;          
			a[1][1] = 3;                    
			
			b[0][0] = 2;          
			b[1][0] = 2;          
			b[0][1] = 2;          
			b[1][1] = 2;                    
			Matrix m = new Matrix("A",a);
			Matrix m2 = new Matrix("B",b);
			double[][] testMatrix = new double[2][2];          
			
			testMatrix[0][0] = 1;          
			testMatrix[1][0] = 1;          
			testMatrix[0][1] = 1;          
			testMatrix[1][1] = 1;                    
			Matrix m3 = new Matrix("test",testMatrix);
			Matrix c = null;
			try {
				c = m.subtract(m2);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}                    
			
			try {
				if (!c.equals(m3))
				{            
				
					fail();  
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

			/*
			 * Method to check that a 10x10 matrix is subtracted correctly
			 */
			public void testSubtractMatrix2()        {      
				
				double[][] a = new double[10][10]; 
			    double[][] b = new double[10][10];    
			    
			    for(int i=0; i<10; i++)  {  
				
			    	for(int j=i; j<10; j++)  {  
				
			    		a[i][j] = (i+1)+(j+1);  
			    	}  
				}    
				for(int i=0; i<10; i++)  {  
				
					for(int j=i; j<10; j++)  {  
				
						b[i][j] = (i+1)+(j+1);  
					}  
				}    
				Matrix m = new Matrix("A",a);
				Matrix m2 = new Matrix("B",b);
				double[][] testMatrix = new double[10][10];
				Matrix m3 = new Matrix("test",testMatrix);
				Matrix subtract = null;
				try {
					subtract = m.subtract(m2);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}  
				
				try {
					if(!subtract.equals(m3))  {  
					fail();
					          }
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}  
			}
 /*Tests a basic case of the crossProduct function
  *@throws Exception
  */
public void testCrossProduct1() throws Exception{
	Vector v = new Vector;
	double [] test1 = new double[3];
	double [] test2 = new double[3];
	
	test1[0] = 1;
    test1[1] = 1;
    test1[2] = 1;
    
    test2[0] = 2;
    test2[1] = 2;
    test2[2] = 2;
    
    double [] product = v.crossProduct(test1,test2);
    
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != 1){
    	fail();
    }
    product = v.crossProduct(test2, test1)
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != 1){
    	fail();
    }
}
/*Tests crossProduct with a basic case where all values are small negative numbers
 * @throws Exception
 */
public void testCrossProduct2() throws Exception{
	Vector v = new Vector;
	double [] test1 = new double[3];
	double [] test2 = new double[3];
	
	test1[0] = -1;
    test1[1] = -1;
    test1[2] = -1;
    
    test2[0] = -2;
    test2[1] = -2;
    test2[2] = -2;
    
    double [] product = v.crossProduct(test1,test2);
    
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != 1){
    	fail();
    }
    product = v.crossProduct(test2, test1)
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != -2){
    	fail();
    }
}
/*Tests the crossProduct function with larger positive values
 * @throws Exception
 */
public void testCrossProduct3() throws Exception{
	Vector v = new Vector;
	double [] test1 = new double[3];
	double [] test2 = new double[3];
	
	test1[0] = 10;
    test1[1] = 10;
    test1[2] = 10;
    
    test2[0] = 15;
    test2[1] = 15;
    test2[2] = 15;
    
    double [] product = v.crossProduct(test1,test2);
    
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != 50){
    	fail();
    }
    product = v.crossProduct(test2, test1)
    if(product[0] != 0){
    	fail();
    }
    if(product[1] != 0){
    	fail();
    }
    if(product[2] != -75){
    	fail();
    }
}
/*Tests the crossProduct function with larger negative numbers
 * @throws Exception
 */
public void testCrossProduct4() throws Exception{
	Vector v = new Vector;
	double [] test1 = new double[3];
	double [] test2 = new double[3];
	
	test1[0] = -10;
    test1[1] = -15;
    test1[2] = -20;
    
    test2[0] = -20;
    test2[1] = -25;
    test2[2] = -30;
    
    double [] product = v.crossProduct(test1,test2);
    
    if(product[0] != -200){
    	fail();
    }
    if(product[1] != 100){
    	fail();
    }
    if(product[2] != 100){
    	fail();
    }
    product = v.crossProduct(test2, test1)
    if(product[0] != 50){
    	fail();
    }
    if(product[1] != -100){
    	fail();
    }
    if(product[2] != -200){
    	fail();
    }
}
/*Tests the crossProduct function with random values, some positive
 *some negative
 *@throws Exception
 */
public void testCrossProduct5() throws Exception{
	Vector v = new Vector;
	double [] test1 = new double[3];
	double [] test2 = new double[3];
	
	test1[0] = -100;
    test1[1] = 35;
    test1[2] = 27;
    
    test2[0] = -45;
    test2[1] = -463;
    test2[2] = 224;
    
    double [] product = v.crossProduct(test1,test2);
    
    if(product[0] != 20341){
    	fail();
    }
    if(product[1] != 21185){
    	fail();
    }
    if(product[2] != 49800){
    	fail();
    }
    product = v.crossProduct(test2, test1)
    if(product[0] != 9899){
    	fail();
    }
    if(product[1] != -21185){
    	fail();
    }
    if(product[2] != 22410){
    	fail();
    }
}
}  
        

